Option Explicit
Sub O_Sample011()
    Dim myCount(1 To 3) As Long         'tX
    Dim myId(1 To 3)    As String        'ܧƭ
    Dim myName(1 To 3)  As String
    Dim myTxtCnt        As Long
    Dim myCmdCnt        As Long
    Dim myTop           As Long
    Dim myLeft          As Long
    Dim myDivH          As Long
    Dim myDivV          As Long
    Dim myUf            As UserForm
    Dim myUfHeight      As Long
    Dim myUfWidth       As Long
    Dim myCnt           As Control
    Dim i               As Long
    Dim j               As Long
    myTop = 20                                 'w檺ܭ
    myLeft = 20
    myDivH = 10
    myDivV = 10
    myName(1) = ""                'w
    myName(2) = "r"
    myName(3) = "Os"
    myId(1) = "Forms.Label.1"         'wW
    myId(2) = "Forms.TextBox.1"       ']Ĥ@ӡ^
    myId(3) = "Forms.CommandButton.1"
    For i = 1 To 3
        myCount(i) = Application.InputBox( _
            Prompt:=myName(i) & "ƶqG", Type:=1)
    Next
    With ThisWorkbook.VBProject.VBComponents.Add(ComponentType:=vbext_ct_MSForm)
        myUfHeight = .Properties("Height")
        myUfWidth = .Properties("Width")
        Set myUf = .Designer
        With myUf
            For i = 1 To 3              'ھڭnsWܧj
                For j = 1 To myCount(i)
                    With .Controls.Add(bstrProgId:=myId(i))
                        .Top = myTop + (j - 1) * (myDivV + .Height)
                        .Left = myLeft
                    End With
                Next
                With .Controls(.Controls.Count - 1)
                    myUfHeight = WorksheetFunction.Max( _
                        .Top + .Height + 20, myUfHeight)
                    myUfWidth = WorksheetFunction.Max( _
                        .Left + .Width + 20, myUfWidth)
                    myLeft = .Left + .Width + 10
                End With
            Next
        End With
        .Properties("Height") = myUfHeight
        .Properties("Width") = myUfWidth
    End With
End Sub
